import threading
import random
import time

beans = list(range(1, 31))
ranking =[]
print(beans)

def pick_bean():
    while len(beans) > 0:
        t = threading.current_thread()
        choice = random.choice(beans)
        beans.remove(choice)
        time.sleep(random.randint(1, 3))
        print(f"{t.name} 捡起了 {choice} 号豆子")
    ranking.append(t.name)
    print(f"{t.name} 完成了比赛")

class ChildMing(threading.Thread):
    def run(self):
        pick_bean()

class ChildHua(threading.Thread):
    def run(self):
        pick_bean()

class ChildChen(threading.Thread):
    def run(self):
        pick_bean()

ming = ChildMing(name="小明")
hua = ChildHua(name="小花")
chen = ChildChen(name="小陈")
ming.start()
hua.start()
chen.start()
ming.join()
hua.join()
chen.join()
print(ranking)